<?php
/**
 * Created by PhpStorm.
 * User: zhangxilu
 * Date: 2018/1/30
 * Time: 下午10:32
 */

namespace common\logic;


use common\models\ReportModel;
use common\models\UserModel;
use yii\db\ActiveQuery;
use yii\helpers\ArrayHelper;

class ReportLogic extends Logic
{

    /**
     * @return ActiveQuery
     */
    protected function _getActiveQuery()
    {
        return ReportModel::find();
    }

    public function getCountByReferee($referee)
    {
        return $this->getCountByParentCode(UserLogic::instance()->getSelfParentCode($referee),$referee);
    }

    public function getCountByParentCode($code,$uid)
    {
        $users = UserLogic::instance()->getQuery(['like', 'parent_code', $code . '%', false], [], ['id'])->all();

        $userids = ArrayHelper::getColumn($users, 'id');
        $userids[] =$uid;
        return $this->getCount(['referee' => $userids]);
    }
}